import { Component, OnInit } from '@angular/core';
import {CreateGameReq, GameApi} from "../../../api/GameApi";
import {ActivatedRoute, Router} from "@angular/router";

@Component({
  selector: 'app-create-game',
  templateUrl: './create-game.component.html',
  styleUrls: ['./create-game.component.scss']
})
export class CreateGameComponent implements OnInit {
  constructor(route: ActivatedRoute, router: Router) {
    this.route = route;
    this.router = router;
  }

  route:ActivatedRoute
  router:Router
  playerCount:number|undefined


  ngOnInit(): void {
  }
  async createHouse(){
    const createGameRespResult = await GameApi.Create(new CreateGameReq(this.playerCount!));
    if(createGameRespResult.success()){
      const houseCode = createGameRespResult.data!.houseCode!;
     await this.router.navigate(['../house',houseCode],{relativeTo:this.route})
    }else{
      createGameRespResult.resolveError(this.router,this.route)
    }
  }
}
